package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class ResultView extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final String BUTTON_DISPOSE = "Hide";
	JTextArea resultText;
	JButton disposeButton;

	public ResultView() {
		createGui();
	}

	public void createGui() {
		// Set app icon
		java.net.URL iconURL = getClass().getResource("/icon.png");
		// iconURL is null when not found
		javax.swing.ImageIcon icon = new javax.swing.ImageIcon(iconURL);
		this.setIconImage(icon.getImage());
		// this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		disposeButton = new JButton(BUTTON_DISPOSE);
		resultText = new JTextArea();
		resultText.setCaretPosition(resultText.getDocument().getLength());

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout());
		buttonPanel.add(disposeButton);

		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new BorderLayout());
		mainPanel.add(new JScrollPane(resultText), BorderLayout.CENTER);
		mainPanel.add(buttonPanel, BorderLayout.SOUTH);

		// Windows size
		final int m_height = 680;
		final int m_width = 900;
		this.setPreferredSize(new Dimension(m_width, m_height));
		// Set positon

		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		final int WIDTH = screenSize.width;
		final int HEIGHT = screenSize.height;
		// Setup the frame accordingly
		// This is assuming you are extending the JFrame //class
		this.setLocation((WIDTH - m_width) / 2, (HEIGHT - m_height) / 2);

		// ... finalize layout
		this.setContentPane(mainPanel);
		this.pack();

		this.setTitle("Results");
		// The window closing event should probably be passed to the
		// Controller in a real program, but this is a short example.
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void setResultContent(String text) {
		this.resultText.setText(text);
	}

	public void addButtonDisposeListener(ActionListener ac) {
		disposeButton.addActionListener(ac);
	}
}
